package testTransfoUML2Java;


import static org.junit.Assert.assertTrue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import astjava.ClassDeclaration;
import astjava.JavaFactory;

import uml2Java.JavaChargeur;
import uml2Java.TransformAssociations;
import uml2Java.TransformPackagesAndTypes;
import uml2Java.UMLChargeur;

public class TestTransformAssociations {
	
	private static org.eclipse.uml2.uml.Package _umlPackage;
	
	private static astjava.Model _javaModel;
	
	private static TransformPackagesAndTypes _transformerTypes;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		_javaModel = JavaFactory.eINSTANCE.createModel();
		UMLChargeur chargeur = new UMLChargeur("modele_de_test/testAssociation.uml");
		_umlPackage = chargeur.loadUMLPackage();
		
		_transformerTypes = new TransformPackagesAndTypes(_umlPackage, _javaModel);
		_transformerTypes.doTransformPackagesAndTypes();
		TransformAssociations transformerAssociations = new TransformAssociations(_transformerTypes);
		transformerAssociations.doTransformAssociation();
	}
	
	@Test
	public void testAssociationUnaryMultiplicity() {
		ClassDeclaration javaClass = (ClassDeclaration) _transformerTypes.get_symbolMap().get("A");
		assertTrue(javaClass.getBodyDeclarations().size() == 2);
		javaClass = (ClassDeclaration) _transformerTypes.get_symbolMap().get("C");
		assertTrue(javaClass.getBodyDeclarations().size() == 2);
		javaClass = (ClassDeclaration) _transformerTypes.get_symbolMap().get("D");
		assertTrue(javaClass.getBodyDeclarations().size() == 2);
	}
	
	@Test
	public void testAssociationNotUnaryMultiplicity() {
		ClassDeclaration javaClassE = (ClassDeclaration) _transformerTypes.get_symbolMap().get("E");
		ClassDeclaration javaClassG = (ClassDeclaration) _transformerTypes.get_symbolMap().get("G");
		ClassDeclaration javaClassH = (ClassDeclaration) _transformerTypes.get_symbolMap().get("H");
		assertTrue(javaClassE.getBodyDeclarations().size() == 1);
		assertTrue(javaClassG.getBodyDeclarations().size() == 1);
		assertTrue(javaClassH.getBodyDeclarations().size() == 1);
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		JavaChargeur chargeur = new JavaChargeur("modele_de_test/testAssociation.astjava");
		chargeur.save(_javaModel);
	}
}
